package tests.delete;

import static org.junit.Assert.*;

import java.net.UnknownHostException;

import model.Budget;
import model.BudgetFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.util.MongoHelper;
import org.workplicity.worklet.WorkletContext;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;


public class BudgetDeleteTest00
{
	
	Budget budget;
	BudgetFactory factory;

    /**
     * Default constructor
     */
    public BudgetDeleteTest00()
    {
    }

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
//		Helper.delete(budget, WorkletContext.getInstance());
	}

	@Test
	public void test()
	{
	 	 factory = new BudgetFactory();
         
	 	 try
		 {
             //Create a budget
 	         budget = (Budget) factory.create();
             budget.setName("Test budget");
             
             budget.setDescription("This is a delete test budget.");
             budget.commit();
              
             Mongo mongo = null;
       		try
       		{
       			mongo = new Mongo();
       		} catch (UnknownHostException e)
       		{
       			// TODO Auto-generated catch block
       			e.printStackTrace();
       		} catch (MongoException e)
       		{
       			// TODO Auto-generated catch block
       			e.printStackTrace();
       		}
       		
               DB db = mongo.getDB("cc");
               DBCollection collection = db.getCollection(budget.getRepositoryName());
               collection.remove(new BasicDBObject("entry.id", budget.getId()));
               
               collection = db.getCollection("Lines");//line.getRepositoryName());
               collection.remove(new BasicDBObject("entry.id", budget.getId()));
               
             
             
             
         }
         catch(Exception e) {
             fail("Creating Budget failed with exception: " + e);
         }
     }
}

